package com.neusoft.databus.policy.converter;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.neusoft.bizcore.web.dto.AbstractConverter;
import com.neusoft.databus.policy.dto.EventAttributeDTO;
import com.neusoft.databus.policy.model.EventAttribute;
import com.neusoft.databus.policy.repository.EventAttibuteRepository;

/**
 * 事件属性Converter
 * 
 * @author naxiang
 */
@Component
public class EventAttributeConverter extends AbstractConverter<EventAttribute, EventAttributeDTO> {
    @Autowired
    private EventAttibuteRepository eventAttibuteRepository;

    @Override
    public EventAttribute toModel(EventAttributeDTO dto) {
        EventAttribute model;
        if (dto.isNew()) {
            model = new EventAttribute();
        } else {
            model = this.eventAttibuteRepository.getOne(dto.getId());
        }
        model.setCount(dto.getCount());
        model.setLastTime(dto.getLastTime());
        model.setContent(dto.getContent());
        return model;
    }

    @Override
    public EventAttributeDTO toDTO(EventAttribute model, boolean forListView) {
        EventAttributeDTO dto = new EventAttributeDTO();
        dto.setId(model.getId());
        dto.setCount(model.getCount());
        dto.setLastTime(model.getLastTime());
        dto.setContent(model.getContent());
        return dto;
    }

}
